﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.SMS.Data;

namespace Wicresoft.SMS.Web
{
    public class CommonController : CustomBaseController
    {

        private ICommonService _commonservice;
        private IUserRoleService _userservice;
        private IUserService _us;

        public CommonController(ICommonService cservice, IUserRoleService uservice)
        {
            _commonservice = cservice;
            _userservice = uservice;
            WebConfigProvider wcp = new WebConfigProvider();
            _us = new UserService(wcp);
        }

        //
        // GET: /Common/
        [ChildActionOnly]
        public ViewResult Menu()
        {
            CommonMenuModel model = new CommonMenuModel();
            model.UserName = User.Identity.Name;

            if (model.UserName != "")
                model.IsActive = _us.GetUserItemByCIL(model.UserName).IsActive == 4 ? 0 : 1;
            else
                model.IsActive = 2;

            model.LoadDepartments(_commonservice.GetDepartments());
            ViewData.Model = model;
            return View();
        }

        [ChildActionOnly]
        public ViewResult UserBanner()
        {

            CommonUseBannerModel model = new CommonUseBannerModel(
                _us.GetUserItemByCIL(User.Identity.Name));

            if (CultureProvider.GetCurrentCultureString() == "zh-cn")
            {
                model.IsZHCN = true;
                model.Url = Request.Path.Replace("zh-cn", "en-us");
            }
            else
            {
                model.IsZHCN = false;
                model.Url = Request.Path.Replace("en-us", "zh-cn");

            }

            model.UserName = model.UserAilas;
            ViewData.Model = model;
            return View();
        }

        [ChildActionOnly]
        public ViewResult Footer()
        {
            WebConfigProvider wcp = new WebConfigProvider();
            UserService us = new UserService(wcp);
            var user = us.GetUserItemByCIL(User.Identity.Name);
            FooterModel fm = new FooterModel();
            fm.IsActive = user.IsActive;
            ViewData.Model = fm;
            return View();
        }

        public ActionResult Certification()
        {
            return File(Url.Content("~/Content/Files/omscer.cer"), "application/x-x509-ca-cert", "omscer.cer");
        }

        public ActionResult OlPlugin()
        {
            return File(Url.Content("~/Content/Files/ClientSetup.msi"), "application/x-msi", "OutlookClientSetup.msi");
        }

        public ActionResult p2003()
        {
            return File(Url.Content("~/Content/Files/2003.exe"), "application/octet-stream", "OutlookClient2003Setup.exe");
        }

        public ActionResult p2007()
        {
            return File(Url.Content("~/Content/Files/2007.exe"), "application/octet-stream", "OutlookClient2007Setup.exe");
        }

        public ActionResult p2010()
        {
            return File(Url.Content("~/Content/Files/2010.exe"), "application/octet-stream", "OutlookClient2010Setup.exe");
        }

        public ActionResult Help(string category)
        {
            switch (category)
            {
                case "Help2003":
                    return View("Help2003");
                case "Help2007":
                    return View("Help2007");
                case "Help2010":
                    return View("Help2010");
                default:
                    return View();

            }            
        }
    }
}
